package com.zhangyang.server;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by ASUS on 2017/10/19.
 */
public class BioServer {
    private int port;
    ServerSocket serverSocket;
    byte buffers[]=new byte[1024];

    public BioServer(int port) throws IOException {
        this.port = port;
        serverSocket=new ServerSocket(port);
    }

    public void listener() throws Exception {
        int i=0;
        while (true) {
            Socket socket=serverSocket.accept();
            InputStream inputStream=socket.getInputStream();
            int len=inputStream.read(buffers);
            if(len>0){
                String stringBuffer=new String(buffers,0,len);
                System.out.println("BioServer get stringBuffer:"+stringBuffer+"..index:"+i);
            }
            inputStream.close();
            i++;
        }
    }

    public static void main(String[] args) throws Exception {
        new BioServer(8080).listener();
    }
}
